﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using Aspose.Words;
using Aspose.Words.Saving;

namespace LibTest
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        static void Main()
        {
            var file = AppDomain.CurrentDomain.BaseDirectory + "2.docx";
            var doc = new Document(file, new LoadOptions(LoadFormat.Docx, string.Empty, null));
            var iso = new ImageSaveOptions(SaveFormat.Jpeg){Resolution = 50};
            for (var i = 0; i < doc.PageCount; i++)
            {
                iso.PageIndex = i;
                iso.PageCount = 1;
                iso.JpegQuality = 100;
                var docStream = new MemoryStream();
                doc.Save(docStream, iso);
                var image = Image.FromStream(docStream);
                var name = AppDomain.CurrentDomain.BaseDirectory + "\\" + i + "_pdf_demo.jpg";
                const string water = @"D:\My Icon\2756\2756\kuang.png";
                ImageWaterParser.AddImageSignPic(image, name, water, 1, 100, 10);
                //var par = doc.Save(AppDomain.CurrentDomain.BaseDirectory + "\\" + i + "_demo.jpg", iso);
                Console.WriteLine("Page: {0}", i);
            }
            Console.WriteLine("Finished.");

            //var wordsRenderAssembly = Assembly.LoadFile(bPath + "Plugins\\WordsRender.dll");
            //var docxFileInfo = new FileInfo(bPath + "1.docx");
            //var documentClassType = wordsRenderAssembly.GetType("Aspose.Words.Document");
            //var docInstance = Activator.CreateInstance(documentClassType, new object[] { bPath + "1.docx" });
            //var property = documentClassType.GetProperty("PageCount", BindingFlags.Public | BindingFlags.GetProperty | BindingFlags.Instance);
            //var pages = (int)property.GetValue(docInstance, null);
            //const BindingFlags bindingFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.InvokeMethod;
            //for (var i = 0; i < pages; i++)
            //{
            //    var savingClassType = wordsRenderAssembly.GetType("Aspose.Words.Saving.ImageSaveOptions");
            //    var saveFormat = wordsRenderAssembly.GetType("Aspose.Words.SaveFormat");
            //    var imageType = Enum.Parse(saveFormat, "Jpeg");
            //    // var field = saveFormat.GetField("Jpeg");
            //    var saveInfo = Activator.CreateInstance(savingClassType, new[] { imageType });
            //    var pageCountproperty = savingClassType.GetProperty("PageCount",
            //                                                        BindingFlags.Public | BindingFlags.GetProperty |
            //                                                        BindingFlags.Instance);
            //    var pageIndexproperty = savingClassType.GetProperty("PageIndex",
            //                                                        BindingFlags.Public | BindingFlags.GetProperty |
            //                                                        BindingFlags.Instance);
            //    pageCountproperty.SetValue(saveInfo, 1, null);
            //    pageIndexproperty.SetValue(saveInfo, i, null);

            //    documentClassType.InvokeMember("Save", bindingFlags, Type.DefaultBinder, docInstance,
            //                                   new[] { bPath + i + ".jpg", saveInfo });
            //}


            Console.ReadKey();
        }
    }
}
